import { gameConfigHandle } from "core/config/gameConfig"
import Random from "core/utils/random"
import utils from "core/utils/utils"
import { PlayerModel } from "core/model/playerModel"
import playerHandle from "./playerHandle"
import { OccType } from "core/typeDefine/typeDefine"

class SpiritHandle {
    refreshChangeItems(player: PlayerModel, rand: Random) {
        let spiritConfig = gameConfigHandle.gameConfig.spirit
        let items = spiritConfig.heroPropList.concat()
        let vipLvl = playerHandle.getVip(player).vipLvl
        let amount = gameConfigHandle.gameConfig.vip.vipAdd.spiritChangeItemAmount[vipLvl]
        player.spirit.changeItems = utils.getRandomArrayNoRepeat(items, amount, rand)
    }
    getOccSpiritLvlTotal(player: PlayerModel, occType: OccType) {
        let total = 0
        let list = gameConfigHandle.gameConfig.spirit.spiritLists[occType]
        list.forEach(id => {
            let lvl = player.spirit.spiritLvls[id] || 0
            total += lvl
        })
        return total
    }
}

let spiritHandle = new SpiritHandle()
export default spiritHandle